<?php

/**
 * social_media_account actions.
 *
 * @package    tmdb
 * @subpackage social_media_account
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class social_media_accountActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    $this->social_media_account_list = Doctrine::getTable('SocialMediaAccount')
      ->createQuery('a')
      ->execute();
  }

  public function executeShow(sfWebRequest $request)
  {
    $this->social_media_account = Doctrine::getTable('SocialMediaAccount')->find(array($request->getParameter('id')));
    $this->forward404Unless($this->social_media_account);
  }

  public function executeNew(sfWebRequest $request)
  {
    $this->form = new SocialMediaAccountForm();
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod('post'));

    $this->form = new SocialMediaAccountForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($social_media_account = Doctrine::getTable('SocialMediaAccount')->find(array($request->getParameter('id'))), sprintf('Object social_media_account does not exist (%s).', array($request->getParameter('id'))));
    $this->form = new SocialMediaAccountForm($social_media_account);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod('post') || $request->isMethod('put'));
    $this->forward404Unless($social_media_account = Doctrine::getTable('SocialMediaAccount')->find(array($request->getParameter('id'))), sprintf('Object social_media_account does not exist (%s).', array($request->getParameter('id'))));
    $this->form = new SocialMediaAccountForm($social_media_account);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($social_media_account = Doctrine::getTable('SocialMediaAccount')->find(array($request->getParameter('id'))), sprintf('Object social_media_account does not exist (%s).', array($request->getParameter('id'))));
    $social_media_account->delete();

    $this->redirect('social_media_account/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()));
    if ($form->isValid())
    {
      $social_media_account = $form->save();

      $this->redirect('social_media_account/edit?id='.$social_media_account['id']);
    }
  }
}
